<!-- 订单页面 -->
<style scoped>
/* 顶部 */
.box {
    background-color: #f4f4f4;
    width: 100%;
    height: 500px;
}

.top {
    width: 100%;
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 40px;
    /* position: fixed;
  top: 0;
  right: 0; */
    /* text-align: center; */
    background-color: white;
}

.button {
    width: 70px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: white;
    border: 1px solid;
    border-radius: 20px;
}

.backspacing {
    width: 20px;
    height: 20px;
}

.null {
    width: 70px;
}

/* 标签页 */
.card {
    width: 95%;
    height: 150px;
    background-color: white;
    margin-left: 2.5%;
    margin-top: 10px;
}

.card_title {
    margin-left: 8px;
    display: flex;
    justify-content: space-between;
}

.card_title p {
    font-weight: 600;
}

.card_all {
    display: flex;
    justify-content: space-around;
}

.card_img {
    width: 30%;
}

.card_img img {
    width: 95%;
    height: 100%;
    border-radius: 15px;
}

.card_particulars {
    width: 65%;
}

.particulars_ticket {
    display: flex;
    justify-content: space-between;
}

.particulars_item {
    display: flex;
    justify-content: space-between;
}

.particulars_img {
    display: flex;
    justify-content: space-between;
}

.particulars_img img {
    width: 17px;
    height: 17px;
}

.operation {
    display: flex;
    align-items: center;
}

.operation div {
    width: 70px;
    height: 30px;
    text-align: center;
    line-height: 30px;
    border: 1px solid #000;
    margin-right: 20px;
    margin-top: 10px;
    border-radius: 5px;
    margin-left: 5px;
}
</style>

<template>
    <div>
        <!-- 顶部导航栏 -->
        <div class="top">
            <button class="button">
                <img src="../assets/zuoz.png" alt="" class="backspacing" @click="BACK" />
                <span>|</span>
                <img src="../assets/home2.png" alt="" class="backspacing" @click="homes" />
            </button>
            <div class="text">订单</div>
            <div class="null"></div>
        </div>

        <!-- 标签页 -->
        <van-tabs v-model:active="active" class="label_Page">
            <van-tab title="全部">
                <div class="card" v-for="item in array" :key="item.id">
                    <div class="card_title">
                        <p>{{ item.scenic_name }}</p>
                        <div>
                            {{
                    item.status === 1
                        ? "交易完成"
                        : item.status === 2
                            ? "待支付"
                            : item.status === 3
                                ? "已取消"
                                : item.status === 4
                                    ? "已支付"
                                    : item.status === 5
                                        ? "已退款"
                                        : "未知状态"
                }}
                        </div>
                    </div>
                    <div class="card_all">
                        <div class="card_img">
                            <img :src="`https://wwz.jingyi.icu${item.img}`" alt="" />
                        </div>
                        <div class="card_particulars">
                            <div class="particulars_ticket">
                                <div>{{ item.name }}</div>
                                <p>￥{{ item.total_price }}</p>
                            </div>
                            <div class="particulars_item">
                                <div>{{ item.create_time }}</div>
                                <p>×1</p>
                            </div>
                            <div class="particulars_img">
                                <div>数量:{{ item.number }}</div>
                                <img src="../assets/12316231.png" alt="" />
                            </div>
                        </div>
                    </div>
                    <div class="operation">
                        <div>删除订单</div>
                        <div>再次购买</div>
                        <div>去评价</div>
                    </div>
                </div>
            </van-tab>
            <van-tab title="交易完成">
                <div class="card" v-for="item in filteredArray" :key="item.id">
                    <div class="card_title">
                        <p>{{ item.scenic_name }}</p>
                        <div>{{ "交易完成" }}</div>
                    </div>
                    <div class="card_all">
                        <div class="card_img">
                            <img :src="`https://wwz.jingyi.icu${item.img}`" alt="" />
                        </div>
                        <div class="card_particulars">
                            <div class="particulars_ticket">
                                <div>{{ item.name }}</div>
                                <p>￥{{ item.total_price }}</p>
                            </div>
                            <div class="particulars_item">
                                <div>{{ item.create_time }}</div>
                                <p>×1</p>
                            </div>
                            <div class="particulars_img">
                                <div>数量:{{ item.number }}</div>
                                <img src="../assets/12316231.png" alt="" />
                            </div>
                        </div>
                    </div>
                    <div class="operation">
                        <div>删除订单</div>
                        <div>再次购买</div>
                        <div>去评价</div>
                    </div>
                </div>
            </van-tab>
            <van-tab title="待支付">
                <div class="card" v-for="item in unpaid" :key="item.id">
                    <div class="card_title">
                        <p>{{ item.scenic_name }}</p>
                        <div>{{ "待支付" }}</div>
                    </div>
                    <div class="card_all">
                        <div class="card_img">
                            <img :src="`https://wwz.jingyi.icu${item.img}`" alt="" />
                        </div>
                        <div class="card_particulars">
                            <div class="particulars_ticket">
                                <div>{{ item.name }}</div>
                                <p>￥{{ item.total_price }}</p>
                            </div>
                            <div class="particulars_item">
                                <div>{{ item.create_time }}</div>
                                <p>×1</p>
                            </div>
                            <div class="particulars_img">
                                <div>数量:{{ item.number }}</div>
                                <img src="../assets/12316231.png" alt="" />
                            </div>
                        </div>
                    </div>
                    <div class="operation">
                        <div>删除订单</div>
                        <div>再次购买</div>
                        <div>去评价</div>
                    </div>
                </div>
            </van-tab>
            <van-tab title="已取消">
                <div class="card" v-for="item in canceled" :key="item.id">
                    <div class="card_title">
                        <p>{{ item.scenic_name }}</p>
                        <div>{{ "已取消" }}</div>
                    </div>
                    <div class="card_all">
                        <div class="card_img">
                            <img :src="`https://wwz.jingyi.icu${item.img}`" alt="" />
                        </div>
                        <div class="card_particulars">
                            <div class="particulars_ticket">
                                <div>{{ item.name }}</div>
                                <p>￥{{ item.total_price }}</p>
                            </div>
                            <div class="particulars_item">
                                <div>{{ item.create_time }}</div>
                                <p>×1</p>
                            </div>
                            <div class="particulars_img">
                                <div>数量:{{ item.number }}</div>
                                <img src="../assets/12316231.png" alt="" />
                            </div>
                        </div>
                    </div>
                    <div class="operation">
                        <div>删除订单</div>
                        <div>再次购买</div>
                        <div>去评价</div>
                    </div>
                </div>
            </van-tab>
            <van-tab title="已支付">
                <div class="card" v-for="item in paid" :key="item.id">
                    <div class="card_title">
                        <p>{{ item.scenic_name }}</p>
                        <div>{{ "已支付" }}</div>
                    </div>
                    <div class="card_all">
                        <div class="card_img">
                            <img :src="`https://wwz.jingyi.icu${item.img}`" alt="" />
                        </div>
                        <div class="card_particulars">
                            <div class="particulars_ticket">
                                <div>{{ item.name }}</div>
                                <p>￥{{ item.total_price }}</p>
                            </div>
                            <div class="particulars_item">
                                <div>{{ item.create_time }}</div>
                                <p>×1</p>
                            </div>
                            <div class="particulars_img">
                                <div>数量:{{ item.number }}</div>
                                <img src="../assets/12316231.png" alt="" />
                            </div>
                        </div>
                    </div>
                    <div class="operation">
                        <div>删除订单</div>
                        <div>再次购买</div>
                        <div>去评价</div>
                    </div>
                </div>
            </van-tab>
            <van-tab title="已退款">
                <div class="card" v-for="item in refunded" :key="item.id">
                    <div class="card_title">
                        <p>{{ item.scenic_name }}</p>
                        <div>{{ "已退款" }}</div>
                    </div>
                    <div class="card_all">
                        <div class="card_img">
                            <img :src="`https://wwz.jingyi.icu${item.img}`" alt="" />
                        </div>
                        <div class="card_particulars">
                            <div class="particulars_ticket">
                                <div>{{ item.name }}</div>
                                <p>￥{{ item.total_price }}</p>
                            </div>
                            <div class="particulars_item">
                                <div>{{ item.create_time }}</div>
                                <p>×1</p>
                            </div>
                            <div class="particulars_img">
                                <div>数量:{{ item.number }}</div>
                                <img src="../assets/12316231.png" alt="" />
                            </div>
                        </div>
                    </div>
                    <div class="operation">
                        <div>删除订单</div>
                        <div>再次购买</div>
                        <div>去评价</div>
                    </div>
                </div>
            </van-tab>
        </van-tabs>
    </div>
</template>

<script setup>
import { ref, onMounted, watch, computed } from "vue";
import { NoticeBar } from "vant";
import { useRouter, useRoute } from "vue-router";
// import { Scenic, intro } from "../api/Home";
import { order } from "../api/me_order";

const uid = JSON.parse(localStorage.getItem("uid")); // 将对象转换为 JSON 字符串并存储
console.log(uid);

console.log(uid.id);
const router = useRouter();
const route = useRoute();
const active = ref(0); // 索引从 0 开始 
// 返回我的页面
function BACK() {
    router.push({
        name: "me",
    });
}
function homes(){
    router.push({
        name: "home",
    });
}
// 浏览记录接口
const array = ref([]);
order({})
    .then((data) => {
        console.log(data);
        array.value = data.data;
        console.log(array.value);
    })
    .catch((err) => {
        console.log(err);
    });

// 交易完成
const filteredArray = computed(() => {
    return array.value.filter((item) => item.status === 1);
});
// 待支付
const unpaid = computed(() => {
    return array.value.filter((item) => item.status === 2);
});
// 已取消
const canceled = computed(() => {
    return array.value.filter((item) => item.status === 3);
});
// 已支付
const paid = computed(() => {
    return array.value.filter((item) => item.status === 4);
});
// 已退款
const refunded = computed(() => {
    return array.value.filter((item) => item.status === 5);
});
</script>